library(readr)
library(tidyverse)
library(forcats)
library(plotly)
library(knitr, warn.conflicts = FALSE, quietly=TRUE)
library(RColorBrewer)
library(stringr)
myPalette <- brewer.pal(8, "YlGn")
vgsales <- read_csv("vgsales.csv")
Rows: 16598 Columns: 11
-- Column specification ---------------------------------------------------------------------------------------
Delimiter: ","
chr (5): Name, Platform, Year, Genre, Publisher
dbl (6): Rank, NA_Sales, EU_Sales, JP_Sales, Other_Sales, Global_Sales

i Use `spec()` to retrieve the full column specification for this data.
i Specify the column types or set `show_col_types = FALSE` to quiet this message.

Anzahl der Videospiele aufgelistet nach Platform

vgsales %>% plot_ly(x=~Platform,color=myPalette[2],stroke=I("black"),name="Amount by Platform") %>% layout(title="Amount by Platform")
No trace type specified:
  Based on info supplied, a 'histogram' trace seems appropriate.
  Read more about this trace type -> https://plotly.com/r/reference/#histogram
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

No trace type specified:
  Based on info supplied, a 'histogram' trace seems appropriate.
  Read more about this trace type -> https://plotly.com/r/reference/#histogram
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels
vgsales %>% plot_ly %>% add_boxplot(x=~Platform,color=myPalette[2],stroke=I("black"),name="Amount by Platform") %>% layout(title="Amount by Platform")
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels
vgsales %>% plot_ly() %>% add_bars(x=~Global_Sales, y=~Platform,color=myPalette[3],name="Sales by Platform (in mio)") %>% layout(title="Sales by Platform (in mio)")
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels
vgsales %>% plot_ly(x=~Publisher,color=myPalette[3],name="Game Amount by Publisher") %>% layout(title="Game Amount by Publisher")
No trace type specified:
  Based on info supplied, a 'histogram' trace seems appropriate.
  Read more about this trace type -> https://plotly.com/r/reference/#histogram
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

No trace type specified:
  Based on info supplied, a 'histogram' trace seems appropriate.
  Read more about this trace type -> https://plotly.com/r/reference/#histogram
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Top Publisher nach Anzahl der Games

grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n()) %>%  
  filter(Anzahl>100)

ordered <- grouped[order(grouped$Anzahl), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
view(removed)

ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "Anzahl"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Anzahl, .desc="true"),
           y=~Anzahl,
           color=myPalette[5],
           name="Game Amount by Publisher") %>% 
  layout(title="Game Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         
         )
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  minimal value for n is 3, returning requested palette with 3 different levels

Top Publisher nach Anzahl der Sales

grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n(),sum(Global_Sales)) %>%
  filter(Anzahl>100) %>%
rename(
    Global_Sales = "sum(Global_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Interactive")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Studios")
ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "Global Sales (in mio)"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="Sales Amount by Publisher") %>% 
  layout(title="Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
LS0tDQp0aXRsZTogIlZEQSBQcm9qZWt0Ig0Kb3V0cHV0OiANCiAgIGh0bWxfZG9jdW1lbnQgOiBkZWZhdWx0DQogICBodG1sX25vdGVib29rIDogZGVmYXVsdA0KLS0tDQoNCg0KYGBge3Igc2V0dXAsIGluY2x1ZGU9VFJVRSwgZWNobz1UUlVFLCBtZXNzYWdlPUZBTFNFfQ0KbGlicmFyeShyZWFkcikNCmxpYnJhcnkodGlkeXZlcnNlKQ0KbGlicmFyeShmb3JjYXRzKQ0KbGlicmFyeShwbG90bHkpDQpsaWJyYXJ5KGtuaXRyLCB3YXJuLmNvbmZsaWN0cyA9IEZBTFNFLCBxdWlldGx5PVRSVUUpDQpsaWJyYXJ5KFJDb2xvckJyZXdlcikNCmxpYnJhcnkoc3RyaW5ncikNCm15UGFsZXR0ZSA8LSBicmV3ZXIucGFsKDgsICJZbEduIikNCnZnc2FsZXMgPC0gcmVhZF9jc3YoInZnc2FsZXMuY3N2IikNCmBgYA0KDQoNCkFuemFobCBkZXIgVmlkZW9zcGllbGUgYXVm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